package cn.aishua.util;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import cn.aishua.R;

import android.content.Context;
import android.content.res.Resources;

public class Utils
{

    public static String doDistance( int d )
    {
        if( d >= 0 && d < 1000 )
        {
            return d + "m";
        }
        NumberFormat formater = DecimalFormat.getInstance();
        formater.setMaximumFractionDigits( 1 );
        return formater.format( (float) d / 1000 ) + "km";
    }

    public static int getIconResId( Context context, String bankName )
    {
        int iconResId = 0;
        if( Constant.BANK_ICON_MAP != null )
        {
            String iconName = Constant.BANK_ICON_MAP.get( bankName );
            if( iconName != null )
            {
                Resources resources = context.getResources();
                iconResId = resources.getIdentifier( context.getPackageName() + ":drawable/"
                    + iconName.split( "[.]" )[0], null, null );
            }
        }

        if( iconResId == 0 )
        {
            iconResId = R.drawable.bank_other;
        }
        return iconResId;
    }

}
